﻿Partial Class WebForm_AddVolunteerControl
    Inherits My.MyUserControl

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.fv.InsertItemTemplate = Me.fv.ItemTemplate
        Me.fv.EditItemTemplate = Me.fv.ItemTemplate
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)
        End If

    End Sub

    Protected Sub btnChangePhotoPath_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        ScriptManager.GetCurrent(Page).RegisterPostBackControl(sender)
    End Sub

    Protected Sub fv_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles fv.DataBound
        CType(Me.fv.FindControl("txtBlackList"), TextBox).Attributes.Add("onblur", "isOver(this,200);")
        CType(Me.fv.FindControl("txtBlackList"), TextBox).Attributes.Add("onkeypress", "isOver1(this,200);")

        Me.BindRDOGender()
        Me.BindDDLParentRegionID(TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList))
        Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList))
        Me.BindDDLParentRegionID(TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList))
        Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList))
        Me.BindRDOIdentificationType()
        Me.BindCHKWishOrganization()
        Me.BindAvailableWorkPeriod()
        Me.BindDDLEducationLevel()
        Me.BindDDLOccupationType()
        Me.BindDDLRetired()
        Me.BindDDLStatus()
        If Me.fv.DataItem IsNot Nothing Then
            Dim ddlItem As DropDownList
            Dim rdoItem As RadioButtonList
            rdoItem = TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList)
            rdoItem.SelectedIndex = rdoItem.Items.IndexOf(rdoItem.Items.FindByValue(DataBinder.Eval(Me.fv.DataItem, "Gender").ToString()))

            ddlItem = TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList)
            ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(DataBinder.Eval(Me.fv.DataItem, "BirthParent").ToString()))
            Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList))
            ddlItem = TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList)
            ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(DataBinder.Eval(Me.fv.DataItem, "BirthVillageID").ToString()))

            ddlItem = TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList)
            ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(DataBinder.Eval(Me.fv.DataItem, "Parent").ToString()))
            Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList))
            ddlItem = TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList)
            ddlItem.SelectedIndex = ddlItem.Items.IndexOf(ddlItem.Items.FindByValue(DataBinder.Eval(Me.fv.DataItem, "VillageID").ToString()))

            '判斷通訊地址是否同戶籍地
            Dim hideSameAddress As Label = TryCast(Me.fv.FindControl("hideSameAddress"), Label)
            If (hideSameAddress.Text = "True") Then
                TryCast(Me.fv.FindControl("chkSameAddress"), CheckBox).Checked = True
            End If
            Me.SetSameAddress()

            '繫結訓練時數
            Me.BindAvailableWorkPeriod()

            If TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text <> "" Then
                If TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text.Substring(1, 1) = "1" Then
                    TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).SelectedValue = "M"
                Else
                    TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).SelectedValue = "F"
                End If
            End If

        End If

        If Me.DataAccessMode <> My.VolunteerDataAccessMode.Register And Me.DataAccessMode <> My.VolunteerDataAccessMode.Approve Then
            If clsAuth.GetUser().VolunteerStatus = My.VolunteerStatus.Approved Or clsAuth.GetUser().VolunteerStatus = My.VolunteerStatus.VBooked Then
                'TryCast(Me.fv.FindControl("txtBasicTrainingHour"), TextBox).Enabled = False
                'TryCast(Me.fv.FindControl("txtSpecialTrainingHour"), TextBox).Enabled = False
                'TryCast(Me.fv.FindControl("txtWorkTrainingHour"), TextBox).Enabled = False
                'TryCast(Me.fv.FindControl("txtWorkHour"), TextBox).Enabled = False

            End If
        End If

        TryCast(Me.fv.FindControl("CustomValidator1"), CustomValidator).Enabled = Me.CauseIDValidation

        '若對此表單有管理權限，則可看到局列管名單 備註
        If HttpContext.Current.User.Identity.Name <> "" AndAlso clsAuth.IsAdministrator Then
            'CType(Me.fv.FindControl("lblBlackList"), Label).Visible = True
            'CType(Me.fv.FindControl("lblBlackListState"), Label).Visible = True
            'CType(Me.fv.FindControl("txtBlackList"), TextBox).Visible = True
            CType(Me.fv.FindControl("phAdmin"), PlaceHolder).Visible = True
        Else
            'CType(Me.fv.FindControl("lblBlackList"), Label).Visible = False
            'CType(Me.fv.FindControl("lblBlackListState"), Label).Visible = False
            'CType(Me.fv.FindControl("txtBlackList"), TextBox).Visible = False
            CType(Me.fv.FindControl("phAdmin"), PlaceHolder).Visible = False
        End If

        ' 服務狀態 預計恢復日
        If MyObj.IsOrgAdmin(clsAuth.GetUserID) Then
            CType(Me.fv.FindControl("phService"), PlaceHolder).Visible = True

        Else

            CType(Me.fv.FindControl("phService"), PlaceHolder).Visible = False

        End If
        'phChangeRecordControl
        If System.IO.Path.GetFileName(Request.PhysicalPath) <> "SelfManageVolunteer.aspx" Then

            phChangeRecordControl.Visible = True
            CType(Me.fv.FindControl("phService"), PlaceHolder).Visible = True


        Else

            phChangeRecordControl.Visible = False
            CType(Me.fv.FindControl("phService"), PlaceHolder).Visible = False

        End If
    End Sub

    Protected Sub gvAvailableWorkPeriod_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Me.chkSet("Sunday", e)
            Me.chkSet("Monday", e)
            Me.chkSet("Tuesday", e)
            Me.chkSet("Wednesday", e)
            Me.chkSet("Thursday", e)
            Me.chkSet("Friday", e)
            Me.chkSet("Saturday", e)
        End If
    End Sub

    Protected Sub chkSet(ByVal WorkTime As String, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Dim chkWorkTime As CheckBox = TryCast(e.Row.FindControl(String.Format("chk{0}", WorkTime)), CheckBox)
        Dim hideWorkTime As HiddenField = TryCast(e.Row.FindControl(String.Format("hide{0}", WorkTime)), HiddenField)
        If (hideWorkTime.Value = "Y") Then
            chkWorkTime.Checked = True
        Else
            chkWorkTime.Checked = False
        End If
    End Sub

    Protected Sub fv_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles fv.ItemCommand
        If e.CommandName = "btnSave" Then
            Me.SetSameAddress()
            If Not Me.OriginalStatus Is Nothing Then
                If Me.Status.ToString.Trim() <> Me.OriginalStatus.ToString.Trim() Then
                    Me.IsChangeStatus = True
                    Me.ChangeRecordControl1.InitAndShow()
                Else
                    Me.IsChangeStatus = False
                End If
            Else
                If Me.Status <> "" Then
                    Me.IsChangeStatus = True
                    Me.ChangeRecordControl1.InitAndShow()
                Else
                    Me.IsChangeStatus = False
                End If

            End If
            RaiseEvent Saving(Me, New EventArgs)
        ElseIf e.CommandName = "btnApprove" Then
            RaiseEvent Approving(Me, New EventArgs)
        ElseIf e.CommandName = "btnReject" Then
            RaiseEvent Rejecting(Me, New EventArgs)
        ElseIf e.CommandName = "btnRestorePassword" Then
            If Me.RestorePassword() = True Then
                MyObj.ShowMessage("更新成功")
            End If
        ElseIf e.CommandName = "btnChangePhotoPath" Then
            If Me.ChangePhotoPath() = True Then
                MyObj.ShowMessage("上傳成功")

                If Me.InitMode = "Init" Then
                    Me.InitData()
                Else
                    Me.InitData(Me.VolunteerID)
                End If

                RaiseEvent PhotoPathChanged(Me, New EventArgs)
            End If
        End If
    End Sub
    Protected Sub ChangeRecordControl1_OK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ChangeRecordControl1.OK_Click
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        sql.Length = 0
        sql.AppendFormat("Insert Into ChangeRecord (ChangeID,VOrganizationID,ChangeType,ChangeReason,CreateDate,CreateBy) ")
        sql.AppendFormat("Select  v.VolunteerID ")
        sql.AppendFormat(",vm.VOrganizationID ")
        sql.AppendFormat(",'ChangeStatus' ")
        sql.AppendFormat(",'{0}' ", Me.ChangeRecordControl1.Reason)
        sql.AppendFormat(",getdate() ")
        sql.AppendFormat(",'{0}' ", clsAuth.GetUserID())
        sql.AppendFormat("from Volunteer v ")
        sql.AppendFormat("left join VOrganizationMapping vm on v.VolunteerID=vm.VolunteerID ")
        sql.AppendFormat("where v.VolunteerID ='{0}' ", Me.VolunteerID)

        dat.AccData(sql)
        MyObj.ShowMessage("儲存成功!")
        RaiseEvent ChangeStatus(Me, New EventArgs)
    End Sub
    '身份證驗證
    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim IDNValidator As New MyIDNValidator.IDNValidator
        If Not IDNValidator.Validate(args.Value) Then
            args.IsValid = False
            TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text = ""
            MyObj.ShowMessage(Me.GetLocalResourceObject("IDNError"))
            Return
        End If
    End Sub
    Protected Sub txtVolunteerID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim IDNValidator As New MyIDNValidator.IDNValidator
        If Not IDNValidator.Validate(TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text.Trim()) Then
            MyObj.ShowMessage(Me.GetLocalResourceObject("IDNError"))
        End If
        TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text = TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text.ToUpper()

        '利用身份證第2碼設定性別
        Dim idn As String = TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text

        If idn.Substring(1, 1) = "1" Then
            TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).SelectedValue = "M"
        Else
            TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).SelectedValue = "F"
        End If
    End Sub

    ''生日檢查
    'Protected Sub txtBirthday_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    '    Dim clsDate As New clsDate()
    '    If Not clsDate.CheckDate(TryCast(Me.fv.FindControl("txtBirthday"), TextBox).Text) Then
    '        MyObj.ShowMessage(Me.GetLocalResourceObject("cvBirthday.ErrorMessage"))
    '    End If
    'End Sub

#Region "戶籍地址與通訊地址相關function"
    Protected Sub ddlBirthParentRegionID_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList))
        Me.SetSameAddress()
    End Sub

    Protected Sub ddlParentRegionID_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList))
    End Sub

    Protected Sub ddlBirthRegionID_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.SetSameAddress()
    End Sub

    Protected Sub txtBirthAddress_OnTextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.SetSameAddress()
    End Sub

    Protected Sub chkSameAddress_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.SetSameAddress()
    End Sub

    Protected Sub SetSameAddress()
        If (TryCast(Me.fv.FindControl("chkSameAddress"), CheckBox).Checked) Then
            TryCast(Me.fv.FindControl("txtBirthAddress"), TextBox).Enabled = False
            TryCast(Me.fv.FindControl("txtBirthAddress"), TextBox).Text = TryCast(Me.fv.FindControl("txtAddress"), TextBox).Text
            TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList).SelectedValue = TryCast(Me.fv.FindControl("ddlParentRegionID"), DropDownList).SelectedValue
            TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList).Enabled = False
            Me.BindDDLRegionID(TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList), TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList))
            TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList).SelectedValue = TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList).SelectedValue
            TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList).Enabled = False
        Else
            TryCast(Me.fv.FindControl("txtBirthAddress"), TextBox).Enabled = True
            TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList).Enabled = True
            TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList).Enabled = True
        End If
    End Sub
#End Region

    Protected Sub fv_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewDeletedEventArgs) Handles fv.ItemDeleted

    End Sub

  
End Class

Partial Class WebForm_AddVolunteerControl

#Region "初始化資料"
    Public Sub InitData()
        Me.InitMode = "Init"
        Me.OriginalVolunteerID = Me.LoginID

        Select Case Me.DataAccessMode
            Case My.VolunteerDataAccessMode.Register
                Me.fv.ChangeMode(FormViewMode.Insert)
                'Me.BindDDLGender()
                'Me.BindRDOIdentificationType()
                'Me.BindCHKWishOrganization()

                '油標起始位置為志工帳號欄位
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Focus()
                '顯示經歷資料
                Me.fv.FindControl("plExperience").Visible = True
            Case My.VolunteerDataAccessMode.SelfManage

                Me.fv.ChangeMode(FormViewMode.Edit)

                Me.BindData(clsAuth.GetUser().VolunteerStatus)

                '隱藏密碼欄位
                'TryCast(Me.fv.FindControl("MultiView1"), MultiView).SetActiveView(TryCast(Me.fv.FindControl("vwResetPassword"), View))

                '隱藏驗證碼欄位
                TryCast(Me.fv.FindControl("MultiView2"), MultiView).Visible = False

                '不可編輯志工帳號
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Enabled = False

                '更改儲存按鍵名稱為[儲存]
                TryCast(Me.fv.FindControl("btnSave"), Button).Text = Me.GetLocalResourceObject("btnSave2.Text")
                TryCast(Me.fv.FindControl("cbSave"), AjaxControlToolkit.ConfirmButtonExtender).ConfirmText = Me.GetLocalResourceObject("cbSave2.ConfirmText")

                '更改志工帳號描述訊息
                If (TryCast(Me.fv.FindControl("lblActive"), Label).Text = "1") Then
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text2")
                ElseIf (TryCast(Me.fv.FindControl("lblActive"), Label).Text = "2") Then
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text3")
                Else
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Visible = False
                End If
            Case My.VolunteerDataAccessMode.Apply
                Me.fv.ChangeMode(FormViewMode.Insert)

                '油標起始位置為志工帳號欄位
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Focus()

                '隱藏希望隸屬單位
                TryCast(Me.fv.FindControl("MultiView4"), MultiView).Visible = False
        End Select
    End Sub

    Public Sub InitData(ByVal volunteerID As String)
        Me.InitMode = "Init2"
        Me.OriginalVolunteerID = volunteerID
        Select Case Me.DataAccessMode
            Case My.VolunteerDataAccessMode.SelfManage
                Me.fv.ChangeMode(FormViewMode.Edit)

                Me.BindData(clsAuth.GetUser().VolunteerStatus)

                '隱藏密碼欄位()
                TryCast(Me.fv.FindControl("MultiView1"), MultiView).SetActiveView(TryCast(Me.fv.FindControl("vwRestorePassword"), View))

                '隱藏驗證碼欄位
                TryCast(Me.fv.FindControl("MultiView2"), MultiView).Visible = False

                '不可編輯志工帳號
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Enabled = False

                '更改儲存按鍵名稱為[儲存]
                TryCast(Me.fv.FindControl("btnSave"), Button).Text = Me.GetLocalResourceObject("btnSave2.Text")
                TryCast(Me.fv.FindControl("cbSave"), AjaxControlToolkit.ConfirmButtonExtender).ConfirmText = Me.GetLocalResourceObject("cbSave2.ConfirmText")

                '更改志工帳號描述訊息
                If (TryCast(Me.fv.FindControl("lblActive"), Label).Text = "1") Then
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text2")
                ElseIf (TryCast(Me.fv.FindControl("lblActive"), Label).Text = "2") Then
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text3")
                Else
                    TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Visible = False
                End If

                If MyObj.VolunteerBasicDataIsCheck(Me.GetVOrganizationID) = True AndAlso clsAuth.GetUser().VolunteerLeader = True AndAlso MyObj.IsSystem(clsAuth.GetUserID()) = False Then
                    TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).Enabled = False
                    TryCast(Me.fv.FindControl("txtVolunteerName"), TextBox).Enabled = False
                    TryCast(Me.fv.FindControl("txtBirthday"), WebForm_CommonControl_CalendarTextBox).Enabled = False
                    TryCast(Me.fv.FindControl("txtOfficePhone"), TextBox).Enabled = False
                    TryCast(Me.fv.FindControl("txtMobilePhone"), TextBox).Enabled = False
                    TryCast(Me.fv.FindControl("ddlEducationLevel"), DropDownList).Enabled = False
                    TryCast(Me.fv.FindControl("ddlRetired"), DropDownList).Enabled = False
                    TryCast(Me.fv.FindControl("ddlOccupationType"), DropDownList).Enabled = False
                    TryCast(Me.fv.FindControl("txtPersonName"), TextBox).Enabled = False
                    TryCast(Me.fv.FindControl("fuPhotoPath"), FileUpload).Enabled = False
                    TryCast(Me.fv.FindControl("btnChangePhotoPath"), Button).Enabled = False
                    TryCast(Me.fv.FindControl("btnWebCam"), Button).Enabled = False
                    TryCast(Me.fv.FindControl("chkSameAddress"), CheckBox).Enabled = False
                    TryCast(Me.fv.FindControl("ddlBirthParentRegionID"), DropDownList).Enabled = False
                    TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList).Enabled = False
                    TryCast(Me.fv.FindControl("txtBirthAddress"), TextBox).Enabled = False
                    TryCast(Me.fv.FindControl("btnRestorePassword"), Button).Enabled = False
                    TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).Enabled = False
                End If



            Case My.VolunteerDataAccessMode.Approve
                Me.fv.ChangeMode(FormViewMode.Edit)
                'MyObj.ShowMessage(My.VolunteerStatus.Approving.Status)
                'Return
                Me.BindData(My.VolunteerStatus.Approving)

                'Return
                '隱藏密碼欄位()
                TryCast(Me.fv.FindControl("MultiView1"), MultiView).SetActiveView(TryCast(Me.fv.FindControl("vwRestorePassword"), View))

                '隱藏驗證碼欄位
                TryCast(Me.fv.FindControl("MultiView2"), MultiView).Visible = False

                '更改儲存按鍵名稱為[儲存]
                TryCast(Me.fv.FindControl("btnSave"), Button).Text = Me.GetLocalResourceObject("btnSave2.Text")
                TryCast(Me.fv.FindControl("cbSave"), AjaxControlToolkit.ConfirmButtonExtender).ConfirmText = Me.GetLocalResourceObject("cbSave2.ConfirmText")

                '更改志工帳號描述訊息
                TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text2")

                '顯示審核按鈕
                TryCast(Me.fv.FindControl("MultiView3"), MultiView).ActiveViewIndex = 1

                '顯示經歷資料
                Me.fv.FindControl("plExperience").Visible = True
            Case My.VolunteerDataAccessMode.Approved
                Me.fv.ChangeMode(FormViewMode.Edit)
                Me.BindData(My.VolunteerStatus.Approved)

                '不可編輯志工帳號
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Enabled = False

                '隱藏密碼欄位()
                TryCast(Me.fv.FindControl("MultiView1"), MultiView).SetActiveView(TryCast(Me.fv.FindControl("vwRestorePassword"), View))


                '隱藏驗證碼欄位
                TryCast(Me.fv.FindControl("MultiView2"), MultiView).Visible = False

                '更改志工帳號描述訊息
                TryCast(Me.fv.FindControl("lblVolunteerIDDescription"), Label).Text = Me.GetLocalResourceObject("lblVolunteerIDDescription.Text3")

                '隱藏儲存按鈕，只能讀取
                TryCast(Me.fv.FindControl("MultiView3"), MultiView).Visible = False
            Case My.VolunteerDataAccessMode.Rejected
                Me.fv.ChangeMode(FormViewMode.Edit)
                Me.BindData(My.VolunteerStatus.Rejected)

                '不可編輯志工帳號
                TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Enabled = False

                '隱藏密碼欄位()
                TryCast(Me.fv.FindControl("MultiView1"), MultiView).SetActiveView(TryCast(Me.fv.FindControl("vwRestorePassword"), View))

                '隱藏驗證碼欄位
                TryCast(Me.fv.FindControl("MultiView2"), MultiView).Visible = False

                '隱藏儲存按鈕，只能讀取
                TryCast(Me.fv.FindControl("MultiView3"), MultiView).Visible = False
        End Select

        '新註冊審核不需顯示招募活動訊息
        If Me.EnlistHeaderID <> "" Then
            '顯示招募活動訊息
            TryCast(Me.fv.FindControl("mvEnlistHeaderInfo"), MultiView).Visible = True
            Me.BindEnlistHeader()
            'Me.BindOrganization() '所屬志工隊
        End If

    End Sub
#End Region

#Region "繫結資料"
    Private Sub BindData()
        Me.BindData(New My.VolunteerStatus(Request.Cookies("VolunteerStatus").Value))
    End Sub

    Private Sub BindData(ByVal volunteerStatus As My.VolunteerStatus)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable = Nothing

        sql.Length = 0
        sql.AppendFormat("select v.*,R1.Parent as BirthParent,R2.Parent,isnull(OA.TrainingHour,0) as BasicTrainingHour ")
        sql.AppendFormat(",isnull(OB.TrainingHour,0) as SpecialTrainingHour,isnull(OC.TrainingHour,0) as WorkTrainingHour ")
        sql.AppendFormat(",isnull(owr.WorkHour,0) as WorkHour ")
        sql.AppendFormat("from Volunteer v ")
        sql.AppendFormat("Left Join Region R1 ON v.BirthVillageID=R1.RegionID ")
        sql.AppendFormat("Left Join Region R2 ON v.VillageID=R2.RegionID ")
        sql.AppendFormat("Left Join OtherTrainingRecord OA ON OA.TrainingType='B' and OA.VolunteerID= '{0}' ", Me.OriginalVolunteerID)
        sql.AppendFormat("Left Join OtherTrainingRecord OB ON OB.TrainingType='S' and OB.VolunteerID= '{0}' ", Me.OriginalVolunteerID)
        sql.AppendFormat("Left Join OtherTrainingRecord OC ON OC.TrainingType='W' and OC.VolunteerID= '{0}' ", Me.OriginalVolunteerID)
        sql.AppendFormat("Left Join OtherWorkRecord owr ON v.VolunteerID = owr.VolunteerID ")
        sql.AppendFormat("where v.VolunteerID = '{0}' ", Me.OriginalVolunteerID)

        If volunteerStatus = My.VolunteerStatus.Approving Then
            dt = dat.GetData(sql)
        ElseIf volunteerStatus = My.VolunteerStatus.Approved Then
            dt = dat.GetData(sql)
        ElseIf volunteerStatus = My.VolunteerStatus.Rejected Then
            dt = dat.GetData(sql)
        ElseIf volunteerStatus = My.VolunteerStatus.VBooked Then
            dt = dat.GetData(sql)
        End If

        Me.fv.DataSource = dt
        Me.fv.DataBind()

        Me.VolunteerStatus = New My.VolunteerStatus(dt.Rows(0)("Active"))
    End Sub

    Private Sub BindEnlistHeader()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim fv As FormView = TryCast(Me.fv.FindControl("fvEnlistHeader"), FormView)

        fv.ChangeMode(FormViewMode.ReadOnly)

        sql.AppendFormat("select eh.* ")
        sql.AppendFormat(",o.OrganizationName ")
        sql.AppendFormat("from EnlistHeader eh ")
        sql.AppendFormat("inner join OrganizationView o on eh.UOrganizationID = o.UOrganizationID ")
        sql.AppendFormat("where eh.EnlistID = {0} ", Me.EnlistHeaderID)

        fv.DataSource = dat.GetData(sql)
        fv.DataBind()
    End Sub

    Private Sub BindAvailableWorkPeriod()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select a.AvailableWorkTime,a.WorkTime as TimeCode,b.* ")
        sql.AppendFormat(" from (select '" + Me.GetLocalResourceObject("WorkTimeA") + "' as AvailableWorkTime,'A' as WorkTime,1 as Sequence ")
        sql.AppendFormat(" union select '" + Me.GetLocalResourceObject("WorkTimeN") + "' as AvailableWorkTime,'N' as WorkTime,2 as Sequence ")
        sql.AppendFormat(" union select '" + Me.GetLocalResourceObject("WorkTimeP") + "' as AvailableWorkTime,'P' as WorkTime,3 as Sequence ")
        sql.AppendFormat(" ) a ")
        sql.AppendFormat(" left join VolunteerWorkTime b ")
        sql.AppendFormat(" on a.WorkTime=b.WorkTime ")
        sql.AppendFormat(" and b.VolunteerID='{0}'", Me.OriginalVolunteerID)
        sql.AppendFormat(" order by a.Sequence ")

        TryCast(Me.fv.FindControl("gvAvailableWorkPeriod"), GridView).DataSource = dat.GetData(sql)
        TryCast(Me.fv.FindControl("gvAvailableWorkPeriod"), GridView).DataBind()

    End Sub

    '所屬志工隊
    Private Sub BindOrganization()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim fvEnlistHeader As FormView = TryCast(Me.fv.FindControl("fvEnlistHeader"), FormView)

        fvEnlistHeader.ChangeMode(FormViewMode.ReadOnly)

        'sql.AppendFormat("Select * from GetVOrganizationTree('{0}') ", DataBinder.Eval(fvEnlistHeader.DataItem, "UOrganizationID").ToString())
        sql.AppendFormat("select * from VOrganizationView where DirectUOrganizationID = '{0}' ", DataBinder.Eval(fvEnlistHeader.DataItem, "UOrganizationID").ToString())

        Dim ddlOrganization As DropDownList = TryCast(fvEnlistHeader.FindControl("ddlOrganization"), DropDownList)
        ddlOrganization.DataTextField = "VOrganizationName"
        ddlOrganization.DataValueField = "VOrganizationID"
        ddlOrganization.DataSource = dat.GetData(sql)
        ddlOrganization.DataBind()
        ddlOrganization.Items.Insert(0, New ListItem(Me.GetLocalResourceObject("PleaseSelect"), ""))

        ddlOrganization.SelectedIndex = ddlOrganization.Items.IndexOf(ddlOrganization.Items.FindByValue(Me.GetVOrganizationID))
    End Sub
#End Region

#Region "戶籍地址與通訊地址相關BindData"
    Private Sub BindDDLParentRegionID(ByVal ddlParentRegionID As DropDownList)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("Select * From Region Where RegionType='T'")
        dt = dat.GetData(sql)

        ddlParentRegionID.DataTextField = "RegionName"
        ddlParentRegionID.DataValueField = "RegionID"
        ddlParentRegionID.DataSource = dt
        ddlParentRegionID.DataBind()
        ddlParentRegionID.Items.Insert(0, New ListItem(Me.GetLocalResourceObject("PleaseSelect"), Me.GetLocalResourceObject("PleaseSelect")))
    End Sub

    Private Sub BindDDLEducationLevel()
        Dim ddlEducationLevel As DropDownList = TryCast(Me.fv.FindControl("ddlEducationLevel"), DropDownList)

        ddlEducationLevel.DataTextField = "Text"
        ddlEducationLevel.DataValueField = "Value"
        ddlEducationLevel.DataSource = MyObj.GetCodeMappingData("Volunteer", "EducationLevel")
        ddlEducationLevel.DataBind()
        ddlEducationLevel.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())

        If TypeOf DataBinder.Eval(fv.DataItem, "EducationLevel") Is DBNull Then
        Else
            ddlEducationLevel.Text = DataBinder.Eval(fv.DataItem, "EducationLevel")
        End If

    End Sub

    Private Sub BindDDLOccupationType()
        Dim ddlOccupationType As DropDownList = TryCast(Me.fv.FindControl("ddlOccupationType"), DropDownList)

        ddlOccupationType.DataTextField = "Text"
        ddlOccupationType.DataValueField = "Value"
        ddlOccupationType.DataSource = MyObj.GetCodeMappingData("Volunteer", "OccupationType")
        ddlOccupationType.DataBind()
        ddlOccupationType.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())

        If TypeOf DataBinder.Eval(fv.DataItem, "OccupationType") Is DBNull Then
        Else
            ddlOccupationType.Text = DataBinder.Eval(fv.DataItem, "OccupationType")
        End If

    End Sub

    Private Sub BindDDLRetired()
        Dim ddlRetired As DropDownList = TryCast(Me.fv.FindControl("ddlRetired"), DropDownList)

        ddlRetired.DataTextField = "Text"
        ddlRetired.DataValueField = "Value"
        ddlRetired.DataSource = MyObj.GetCodeMappingData("Volunteer", "Retired")
        ddlRetired.DataBind()
        ddlRetired.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())

        If TypeOf DataBinder.Eval(fv.DataItem, "Retired") Is DBNull Then
        Else
            ddlRetired.Text = DataBinder.Eval(fv.DataItem, "Retired")
        End If

    End Sub

    Private Sub BindDDLStatus()
        Dim ddlStatus As DropDownList = TryCast(Me.fv.FindControl("ddlStatus"), DropDownList)

        ddlStatus.DataTextField = "Text"
        ddlStatus.DataValueField = "Value"
        ddlStatus.DataSource = MyObj.GetCodeMappingData("Volunteer", "Status")
        ddlStatus.DataBind()
        ddlStatus.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())

        If TypeOf DataBinder.Eval(fv.DataItem, "Status") Is DBNull Then
        Else
            ddlStatus.Text = DataBinder.Eval(fv.DataItem, "Status")
            Me.OriginalStatus = ddlStatus.Text.Trim()
        End If

     
    End Sub
    Private Sub BindDDLRegionID(ByVal ddlParentRegionID As DropDownList, ByVal ddlRegionID As DropDownList)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select * from region where RegionType='V'")
        sql.AppendFormat(" and Parent='{0}'", ddlParentRegionID.SelectedValue)
        dt = dat.GetData(sql)

        ddlRegionID.DataTextField = "RegionName"
        ddlRegionID.DataValueField = "RegionID"
        ddlRegionID.DataSource = dt
        ddlRegionID.DataBind()
        ddlRegionID.Items.Insert(0, New ListItem(Me.GetLocalResourceObject("PleaseSelect"), Me.GetLocalResourceObject("PleaseSelect")))
    End Sub

    Private Sub BindRDOGender()
        TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).DataTextField = "Text"
        TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).DataValueField = "Value"
        TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).DataSource = MyObj.GetCodeMappingData("Volunteer", "Gender")
        TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).DataBind()
    End Sub

    Private Sub BindRDOIdentificationType()
        TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).DataTextField = "Text"
        TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).DataValueField = "Value"
        TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).DataSource = MyObj.GetCodeMappingData("Volunteer", "IdentificationType")
        TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).DataBind()

        TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).SelectedIndex = 0
    End Sub

    Private Sub BindCHKWishOrganization()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable
        Dim i As Integer

        sql.AppendFormat("select a.OrganizationID,a.OrganizationName,CASE ISNULL(b.OrganizationID,0) WHEN 0 THEN 0 ELSE 1 END IsChecked ")
        sql.AppendFormat("from Organization a ")
        sql.AppendFormat("Left Join WishOrganization b on ")
        sql.AppendFormat("  a.OrganizationID=b.OrganizationID ")
        sql.AppendFormat("  and b.VolunteerID='" & Me.OriginalVolunteerID & "'")
        sql.AppendFormat("where Active='Y' and Parent='15' and Internal='N' ")
        dt = dat.GetData(sql.ToString(), Nothing, Data.CommandType.Text, "dt").Tables(0)

        TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).DataTextField = "OrganizationName"
        TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).DataValueField = "OrganizationID"
        TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).DataSource = dt
        TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).DataBind()

        For i = 0 To dt.Rows.Count - 1
            TryCast(Me.fv.FindControl("chkWishOrganization"), CheckBoxList).Items(i).Selected = Convert.ToBoolean(dt.Rows(i)("IsChecked"))
        Next
    End Sub
#End Region

#Region "屬性"
    Public Property OriginalStatus() As String
        Get
            Return ViewState("OriginalStatus")
        End Get
        Set(ByVal value As String)
            ViewState("OriginalStatus") = value
        End Set
    End Property
    Public Property DataAccessMode() As My.VolunteerDataAccessMode
        Get
            If ViewState("DataAccessMode") Is Nothing Then
                Return My.VolunteerDataAccessMode.Register
            End If

            Return ViewState("DataAccessMode")
        End Get
        Set(ByVal value As My.VolunteerDataAccessMode)
            ViewState("DataAccessMode") = value
        End Set
    End Property

    Public ReadOnly Property FormData(ByVal id As String) As Control
        Get
            Return Me.fv.FindControl(id)
        End Get
    End Property

    Public Property VolunteerStatus() As My.VolunteerStatus
        Get
            Return ViewState("VolunteerStatus")
        End Get
        Set(ByVal value As My.VolunteerStatus)
            ViewState("VolunteerStatus") = value
        End Set
    End Property

    Private ReadOnly Property LoginID() As String
        Get
            Return Context.User.Identity.Name
        End Get
    End Property

    Public Property OriginalVolunteerID() As String
        Get
            Return ViewState("OriginalVolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("OriginalVolunteerID") = value
        End Set
    End Property

    Public Property EnlistHeaderID() As String
        Get
            Return ViewState("EnlistHeaderID")
        End Get
        Set(ByVal value As String)
            ViewState("EnlistHeaderID") = value
        End Set
    End Property

    '使用者所輸入的驗證碼
    'Public ReadOnly Property MyVerificationCode() As String
    '    Get
    '        Return TryCast(Me.fv.FindControl("txtVerificationCode"), TextBox).Text.ToUpper()
    '    End Get
    'End Property

    '系統產生的驗證碼
    'Public ReadOnly Property VerificationCode() As String
    '    Get
    '        Return TryCast(Me.fv.FindControl("VerificationCode1"), Public_VerificationCode).VerificationCode
    '    End Get
    'End Property

    Public ReadOnly Property VolunteerID() As String
        Get
            Return TryCast(Me.fv.FindControl("txtVolunteerID"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property EcolifeID() As String
        Get
            Return TryCast(Me.fv.FindControl("txtEcolifeID"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property VolunteerName() As String
        Get
            Return TryCast(Me.fv.FindControl("txtVolunteerName"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property VolunteerPassword() As String
        Get
            Return TryCast(Me.fv.FindControl("txtVolunteerPassword"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property ConfirmPassword() As String
        Get
            Return TryCast(Me.fv.FindControl("txtConfirmPassword"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property IdentificationType() As String
        Get
            Return TryCast(Me.fv.FindControl("rdoIdentificationType"), RadioButtonList).SelectedValue
        End Get
    End Property
    Public Property IsChangeStatus() As Boolean
        Get
            Return ViewState("IsChangeStatus")
        End Get
        Set(ByVal value As Boolean)
            ViewState("IsChangeStatus") = value
        End Set
    End Property
    '可服務狀態
    Public ReadOnly Property Status() As String
        Get
            Return IIf(TryCast(Me.fv.FindControl("ddlStatus"), DropDownList) Is Nothing, "", TryCast(Me.fv.FindControl("ddlStatus"), DropDownList).SelectedValue)
        End Get
    End Property
    '預計回復日
    Public ReadOnly Property RecoverDate() As Date
        Get
            Return DateTime.Parse(TryCast(Me.fv.FindControl("txtRecoverDate"), WebForm_CommonControl_CalendarTextBox).Text)
        End Get
    End Property

    '備註
    Public ReadOnly Property Comment() As String
        Get
            Return TryCast(Me.fv.FindControl("txtComment"), TextBox).Text
        End Get
    End Property
    '局列管名單
    Public ReadOnly Property BlackList() As String
        Get
            Return TryCast(Me.fv.FindControl("txtBlackList"), TextBox).Text
        End Get
    End Property

    '所屬民間團體
    Public ReadOnly Property PersonName() As String
        Get
            Return TryCast(Me.fv.FindControl("txtPersonName"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property RegionID() As String
        Get
            Return TryCast(Me.fv.FindControl("ddlRegionID"), DropDownList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property BirthRegionID() As String
        Get
            Return TryCast(Me.fv.FindControl("ddlBirthRegionID"), DropDownList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property WishOrganization() As String()
        Get
            Dim chkWishOrganization As CheckBoxList = CType(Me.fv.FindControl("chkWishOrganization"), CheckBoxList)
            Dim sWishOrganization(chkWishOrganization.Items.Count) As String
            Dim i, j As Integer
            j = 0
            For i = 0 To chkWishOrganization.Items.Count - 1
                If (chkWishOrganization.Items(i).Selected) Then
                    sWishOrganization(j) = chkWishOrganization.Items(i).Value
                    j += 1
                End If
            Next
            Return sWishOrganization
        End Get
    End Property

    Public ReadOnly Property Gender() As String
        Get
            Return TryCast(Me.fv.FindControl("rdoGender"), RadioButtonList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property Birthday() As DateTime
        Get
            Return DateTime.Parse(TryCast(Me.fv.FindControl("txtBirthday"), WebForm_CommonControl_CalendarTextBox).Text)
        End Get
    End Property

    Public ReadOnly Property MobilePhone() As String
        Get
            Return TryCast(Me.fv.FindControl("txtMobilePhone"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property OfficePhone() As String
        Get
            Return TryCast(Me.fv.FindControl("txtOfficePhone"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property SameAddress() As String
        Get
            If (TryCast(Me.fv.FindControl("chkSameAddress"), CheckBox).Checked) Then
                Return "1"
            Else
                Return "0"
            End If
        End Get
    End Property

    Public ReadOnly Property BirthAddress() As String
        Get
            Return TryCast(Me.fv.FindControl("txtBirthAddress"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property Address() As String
        Get
            Return TryCast(Me.fv.FindControl("txtAddress"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property EmergentPerson() As String
        Get
            Return TryCast(Me.fv.FindControl("txtEmergentPerson"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property EmergentPhone() As String
        Get
            Return TryCast(Me.fv.FindControl("txtEmergentPhone"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property Email() As String
        Get
            Return TryCast(Me.fv.FindControl("txtEmail"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property EducationLevel() As String
        Get
            Return TryCast(Me.fv.FindControl("ddlEducationLevel"), DropDownList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property OccupationType() As String
        Get
            Return TryCast(Me.fv.FindControl("ddlOccupationType"), DropDownList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property Retired() As String
        Get
            Return TryCast(Me.fv.FindControl("ddlRetired"), DropDownList).SelectedValue
        End Get
    End Property

    Public ReadOnly Property OtherBasicTrainingHour() As Integer
        Get
            Return TryCast(Me.fv.FindControl("BasicTrainingHour"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property OtherSpecialTrainingHour() As Integer
        Get
            Return TryCast(Me.fv.FindControl("SpecialTrainingHour"), TextBox).Text
        End Get
    End Property

    Public ReadOnly Property WorkTime() As String(,)
        Get
            Dim SetTime(3, 7) As String
            For i As Integer = 0 To 2
                SetTime(i, 0) = chkSet(i, "Sunday")
                SetTime(i, 1) = chkSet(i, "Monday")
                SetTime(i, 2) = chkSet(i, "Tuesday")
                SetTime(i, 3) = chkSet(i, "Wednesday")
                SetTime(i, 4) = chkSet(i, "Thursday")
                SetTime(i, 5) = chkSet(i, "Friday")
                SetTime(i, 6) = chkSet(i, "Saturday")
            Next
            Return SetTime
        End Get
    End Property

    Public ReadOnly Property TrainingHour() As String()
        Get
            Dim GetHour(3) As String
            GetHour(0) = TryCast(Me.fv.FindControl("txtBasicTrainingHour"), TextBox).Text
            GetHour(1) = TryCast(Me.fv.FindControl("txtSpecialTrainingHour"), TextBox).Text
            GetHour(2) = TryCast(Me.fv.FindControl("txtWorkTrainingHour"), TextBox).Text
            Return GetHour
        End Get
    End Property

    '已服務時數累計
    Public ReadOnly Property OtherWorkHour() As String
        Get
            If TryCast(Me.fv.FindControl("txtWorkHour"), TextBox).Text = "" Then
                TryCast(Me.fv.FindControl("txtWorkHour"), TextBox).Text = "0"
            End If

            Return TryCast(Me.fv.FindControl("txtWorkHour"), TextBox).Text
        End Get
    End Property

    '讀取所屬志工隊
    Public Property GetVOrganizationID() As String
        Get
            Return ViewState("GetVOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("GetVOrganizationID") = value
        End Set
    End Property

    '回傳所屬志工隊
    Public ReadOnly Property VOrganizationID() As String
        Get
            Dim fvEnlistHeader As FormView = TryCast(Me.fv.FindControl("fvEnlistHeader"), FormView)
            Return TryCast(fvEnlistHeader.FindControl("ddlOrganization"), DropDownList).SelectedValue
        End Get
    End Property

    '活動EndDate
    Public ReadOnly Property EndDate() As DateTime
        Get
            Dim fvEnlistHeader As FormView = TryCast(Me.fv.FindControl("fvEnlistHeader"), FormView)
            Return DateTime.Parse(TryCast(fvEnlistHeader.FindControl("lblEndDate"), Label).Text)
        End Get
    End Property

    Protected Function chkSet(ByVal index As Integer, ByVal WorkTime As String) As String
        Dim gv As GridView = TryCast(Me.fv.FindControl("gvAvailableWorkPeriod"), GridView)
        Dim chkWorkTime As CheckBox = TryCast(gv.Rows(index).FindControl(String.Format("chk{0}", WorkTime)), CheckBox)
        If (chkWorkTime.Checked) Then
            Return "Y"
        Else
            Return "N"
        End If
    End Function

    Public Property CauseIDValidation() As Boolean
        Get
            If ViewState("CauseIDValidation") Is Nothing Then
                Return False
            End If

            Return False
        End Get
        Set(ByVal value As Boolean)
            ViewState("CauseIDValidation") = value
        End Set
    End Property

    Public ReadOnly Property PhotoPathBase() As String
        Get
            If ViewState("PhotoPathBase") Is Nothing Then
                ViewState("PhotoPathBase") = MyObj.GetFilePath("VolunteerPhoto")
            End If

            Return ViewState("PhotoPathBase")
        End Get
    End Property

    Public ReadOnly Property PhotoHeight() As String
        Get
            If ViewState("PhotoHeight") Is Nothing Then
                ViewState("PhotoHeight") = MyObj.GetParameter("Volunteer", "VBookPhotoHeight")
            End If

            Return ViewState("PhotoHeight")
        End Get
    End Property

    Public ReadOnly Property PhotoWidth() As String
        Get
            If ViewState("PhotoWidth") Is Nothing Then
                ViewState("PhotoWidth") = MyObj.GetParameter("Volunteer", "VBookPhotoWidth")
            End If

            Return ViewState("PhotoWidth")
        End Get
    End Property

    Public Property InitMode() As String
        Get
            If ViewState("InitMode") Is Nothing Then
                ViewState("InitMode") = "Init"
            End If

            Return ViewState("InitMode")
        End Get
        Set(ByVal value As String)
            ViewState("InitMode") = value
        End Set
    End Property
#End Region

#Region "事件"
    Public Event Saving(ByVal sender As Object, ByVal e As EventArgs)
    Public Event Approving(ByVal sender As Object, ByVal e As EventArgs)
    Public Event Rejecting(ByVal sender As Object, ByVal e As EventArgs)
    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event ChangeStatus(ByVal source As Object, ByVal e As EventArgs)
#End Region
End Class

Partial Class WebForm_AddVolunteerControl
#Region "BLL"

    ''' <summary>
    ''' 預設密碼 = 身份證後2碼 + 生日 MMDD
    ''' </summary>
    ''' <remarks></remarks>
    Public Function RestorePassword() As Boolean
        Return clsUser.RestorePassword(Me.VolunteerID, Me.Birthday)

        'Return True
    End Function

    Public Function ChangePhotoPath() As Boolean
        Dim fu As FileUpload = TryCast(Me.fv.FindControl("fuPhotoPath"), FileUpload)

        If fu.HasFile = False Then
            MyObj.ShowMessage("未選擇檔案")
            Return False
        End If

        Dim originalFileName As String = Server.MapPath(Me.PhotoPathBase + TryCast(Me.fv.FindControl("imgPhoto"), Image).AlternateText)

        Dim fileName As String = Server.MapPath(Me.PhotoPathBase + Me.VolunteerID + System.IO.Path.GetExtension(fu.FileName))

        If System.IO.File.Exists(originalFileName) = True Then
            System.IO.File.Delete(originalFileName)
        End If

        fu.SaveAs(fileName)
        '
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("update v set ")
        sql.AppendFormat("PhotoPath = '{0}' ", System.IO.Path.GetFileName(fileName))
        sql.AppendFormat("from Volunteer v ")
        sql.AppendFormat("where v.VolunteerID = '{0}' ", Me.VolunteerID)

        dat.AccData(sql)

        Return True
    End Function

    Public Event PhotoPathChanged(ByVal source As Object, ByVal e As EventArgs)
#End Region
End Class